﻿function EnableContent(user, actionUrl) {
    var useTables = $("[id=Tables_" + user + "]:checked").val() !== undefined;
    var useBlobs = $("[id=Blobs_" + user + "]:checked").val() !== undefined;

    actionUrl = actionUrl.replace("_user_", user);
    actionUrl = actionUrl.replace("_useTables_", useTables);
    actionUrl = actionUrl.replace("_useBlobs_", useBlobs);

    $.ajax({ url: actionUrl, cache: false });
}

function SetPublic(table, actionUrl) {
    var isPublic = $("#Public_" + table + ":checked").val() !== undefined;

    actionUrl = actionUrl.replace("_table_", table);
    actionUrl = actionUrl.replace("_isPublic_", isPublic);

    $("input[name^='" + table + "'][type='checkbox']").each(function (ix, el) {
        el.disabled = isPublic;
    });

    $.ajax({ url: actionUrl, cache: false });
}

function SetPermission(table, user, addTablePermissionnActionUrl, removeTablePermissionActionUrl) {
    var hasAccess = $("[id=" + table + "_" + user + "]:checked").val() !== undefined;
    var actionUrl = '';

    if (hasAccess)
        actionUrl = addTablePermissionnActionUrl;
    else
        actionUrl = removeTablePermissionActionUrl;

    actionUrl = actionUrl.replace("_table_", table);
    actionUrl = actionUrl.replace("_user_", user);

    $.ajax({ url: actionUrl, cache: false });
}